f<template>
  <div id="boxlist" class="flex" style="flex:1; ">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
        <div novalidate class="form-inline" partial>
          <div class="form-group">
            <input type="text" class="form-control" v-model="model.f_adjustable_id"
            condition="a.f_adjustable_id like '%{}%'" placeholder='调压箱编号'>
          </div>
          <div class="form-group">
            <input type="text" class="form-control" v-model="model.f_adjustable_name"
            condition="f_adjustable_name like '%{}%'" placeholder='调压箱名称'>
          </div>
          <div class="form-group">
            <input type="text" class="form-control" v-model="model.f_adjustable_address"
            condition="f_adjustable_address like '%{}%'" placeholder='调压箱地址'>
          </div>
          <div class="form-group" >
            <v-select :value.sync="model.f_filiale" v-model='model.f_filiale'
            :options='$parent.$parent.filiales' placeholder='分公司'
            close-on-select
            condition="f_filiale = '{}'"></v-select>
          </div>

          <div class="form-group">
            <v-select :value.sync="model.f_outlets" v-model='model.f_outlets'
                :options='$parent.$parent.outlets' placeholder='营业网点'
                close-on-select
                condition="f_outlets = '{}'"></v-select>
          </div>

          <div class="form-group">
            <button class="btn btn-success width-80" @click="$parent.$parent.search()" v-el:cx>查询</button>
          </div>
          <div class="form-group">
            <button class="btn btn-success width-80" @click="$parent.$parent.createNew()" v-el:cx>新建</button>
          </div>
          <div class="form-group">
            <export-excel :data="{orderitem: 'f_adjustable_id',condition: $parent.model.condition}" bean="调压箱导出" sqlurl="rs/logic/exportfile"></export-excel>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th>序号</th>
            <th>调压箱编号</th>
            <th>调压箱名称</th>
            <th>调压箱地址</th>
            <th>用户数</th>
            <th>操作</th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center;">{{$index+1}}</td>
          <td>{{row.f_adjustable_id}}</td>
          <td>{{row.f_adjustable_name}}</td>
          <td>{{row.f_adjustable_address}}</td>
          <td>{{row.counts}}</td>
          <td style="text-align:center">
            <button class="btn btn-link "   v-if = "row.counts === 0" @click.stop="$parent.$parent.$parent.del(row.f_adjustable_id)"> 删除 </button>
          </td>
        </template>
      </data-grid>
  </criteria-paged>
 </div>
</template>
<script>
import { PagedList } from 'vue-client'
import * as Util from '../../Util'
// import AppData from '../../../../stores/AppData'

export default {
  title: '调压箱',
  data () {
    return {
      model: new PagedList('rs/sql/adjustableboxQuery', 20)
    }
  },
  ready () {
    this.search()
  },
  methods: {
    search () {
      if (Util.f.parent.orgtype !== '总公司') {
        this.$refs.paged.$refs.cri.model.f_filiale = [Util.f.f_fengongsi]
      }
      this.$dispatch('search')
    },
    selfSearch (args) {
      this.model.search(args.condition, args.model)
    },
    createNew () {
      console.log('123123')
      this.$dispatch('add')
    },
    del (id) {
      this.$showMessage('确认删除吗?', ['confirm', 'cancel']).then(
        (response) => {
          if (response === 'confirm') {
            this.$resetpost('rs/logic/deleteBox', {data: {id: id}}, {resolveMsg: '删除成功', rejectMsg: '删除失败'})
            .then((res) => { this.$dispatch('success', '调压箱删除', this.data, res) })
            .catch((error) => { this.$dispatch('error', '调压箱删除', this.data, error) })
          } else if (response === 'cancel') {
            this.$dispatch('cancel')
          }
        })
    }
  },
  computed: {
    filiales () {
      let rs = []
      for (let i = 0; i < Util.f.f_allfiliale.length; i++) {
        rs.push({label: Util.f.f_allfiliale[i].label, value: Util.f.f_allfiliale[i].label})
      }
      return [{label: '全部', value: ''}, ...rs]
    },
    outlets () {
      let rs = []
      console.log('档案营业网点。。。', this.$refs.paged.$refs.cri.model.f_filiale)
      if (this.$refs.paged.$refs.cri.model.f_filiale.length > 0) {
        for (let i = 0; i < Util.f.f_allfiliale.length; i++) {
          if (Util.f.f_allfiliale[i].label === this.$refs.paged.$refs.cri.model.f_filiale[0]) {
            rs = Util.f.f_allfiliale[i].value
          }
        }
      }
      console.log('获取档案营业网点。。。。', rs)
      return [{label: '全部', value: ''}, ...rs]
    }
  }
}
</script>
